﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MidTestLib.Interface;

namespace MidTestLib.Data
{
    public class SimpleEncryption : Encryption, IEncryption
    {
        #region Method
        public bool Encrypt(ref string input, string step)
        {
            if (Validate(input, ValidateType.Alpha) && Validate(step, ValidateType.Numeric))
            {
                char[] char_arr = input.ToCharArray();
                for (int i = 0; i < char_arr.Length; i++ )
                {
                    for (int j = 0; j < Int32.Parse(step); j++)
                    {
                        char_arr[i] = Increment(char_arr[i]);
                    }
                }
                input = new string(char_arr);
                return true;
            }
            return false;
        }

        public bool Decrypt(ref string input, string step)
        {
            if (Validate(input, ValidateType.Alpha) && Validate(step, ValidateType.Numeric))
            {
                char[] char_arr = input.ToCharArray();
                for (int i = 0; i < char_arr.Length; i++)
                {
                    for (int j = 0; j < Int32.Parse(step); j++)
                    {
                        char_arr[i] = Decrement(char_arr[i]);
                    }
                }
                input = new string(char_arr);
                return true;
            }
            return false;
        }
        #endregion
    }
}
